package com.example.gpstest;

import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.app.Activity;

public class MainActivity extends Activity {
	LocationManager lm; 
	LocationListener providerGpsListener=null;
	LocationListener deviceGpsListener=null;
	
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		providerGpsListener=new ProviderGpsListener(this);
		deviceGpsListener=new DeviceGpsListener(this);
		lm = (LocationManager) getSystemService(LOCATION_SERVICE);
	}
	
	protected void onResume() {
		/*
		 * add location listener and request updates every 1000ms or 10m
		 */
		lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1000, 10f, providerGpsListener);
		lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 10f, deviceGpsListener);
		super.onResume();
	}
	
	protected void onPause() {
		/* GPS, as it turns out, consumes battery like crazy */
		lm.removeUpdates(providerGpsListener);
		lm.removeUpdates(deviceGpsListener);
		super.onPause();
	}

	

	protected void onStop() {
		/* may as well just finish since saving the state is not important for this toy app */
		finish();
		super.onStop();
	}
}
